home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-23 | 16.9 KB | 558 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UTwistDownControl.cp
- // ETO20 MacApp 3.3.1, MPW 3.4.1
- // Copyright ©1994-1996 Conrad Kopala
- // Twist Down Lists version 2.0a0 7/15/96
- //----------------------------------------------------------------------------------------
-
- #ifndef __UTWISTDOWNCONTROL__
- #include "UTwistDownControl.h"
- #endif
-
- //The following is required for gAppleEventRouting
- #ifndef __UTWISTDOWNAPP__
- #include "UTwistDownApp.h"
- #endif
-
- //The following is required for TTwistDownView in TExpandElementCommand::MakeAppleEvent
- //and TCollapseElementCommand::MakeAppleEvent.
- #ifndef __UTWISTDOWNVIEW__
- #include "UTwistDownView.h"
- #endif
-
- #ifndef __UTWISTDOWNDOCUMENT__
- #include "UTwistDownDocument.h"
- #endif
-
- #ifndef __UTWISTDOWNELEMENT__
- #include "UTwistDownElement.h"
- #endif
-
- #ifndef __UTWISTDOWNGLOBALS__
- #include "UTwistDownGlobals.h"
- #endif
-
- //MacApp stuff
- //None
-
- //ToolBox stuff
-
- #ifndef __AEREGISTRY__
- #include "AERegistry.h"
- #endif
-
- //ANSI stuff
- //None
- //========================================================================================
- // Global Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUTwistDownControl:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- void InitUTwistDownControl()
- {
- MA_REGISTER_CLASS(TTwistDownControl);
- }
-
- //========================================================================================
- // CLASS TTwistDownControl
- //========================================================================================
- #undef Inherited
- #define Inherited TControl
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TTwistDownControl, Inherited);
- //----------------------------------------------------------------------------------------
- // TTwistDownControl constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TTwistDownControl::TTwistDownControl()
- {
- fTwistDownElement = NULL;
- fTwistDownDocument = NULL;
- fTwistDownView = NULL;
- fHiliteState = noHilite;
- fNewHiliteState = noHilite;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::~TTwistDownControl
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TTwistDownControl::~TTwistDownControl()
- {
-
- if (fTwistDownView)
- fTwistDownView -> DecrementNumberOfControls();
-
- if (fTwistDownElement)
- fTwistDownElement -> SetTwistDownControlTo(NULL);
-
- fTwistDownElement = NULL;
- fTwistDownDocument = NULL;
- fTwistDownView = NULL;
- fHiliteState = noHilite;
- fNewHiliteState = noHilite;
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::ITwistDownControl:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownControl::ITwistDownControl(VPoint& itsLocation, TTwistDownElement* itsTwistDownElement,
- TTwistDownView* itsSuperView)
- {
- fIdentifier = kTwistDownControlViewID; //Not really needed but useful when debugging
- //because it allows you to identify a twistDowncontrol.
- fTwistDownElement = itsTwistDownElement;
- fTwistDownView = itsSuperView;
-
- VPoint itsSize = gZeroVPt;
-
- if (fTwistDownView)
- itsSize = fTwistDownView -> GetTwistDownControlSize();
-
- TextStyle theTextStyle = gApplicationStyle;
-
- if (itsSuperView)
- theTextStyle = itsSuperView -> fTextStyle;
-
- this -> IControl(itsSuperView,itsLocation, itsSize, sizeFixed, sizeFixed, theTextStyle);
-
- fHandlesFirstClicks = FALSE;
-
- fHelpID = kTwistDowncontrolHelp;
- fHelpIndex = 1;
-
- if (fDocument)
- {
- fTwistDownDocument = (TTwistDownDocument*)fDocument;
-
- if (fTwistDownView)
- {
- fTwistDownView -> IncrementNumberOfControls();
-
- if (fTwistDownView -> ControlCountingEnabled() != TRUE)
- fTwistDownView -> IncrementInitialNumberOfControls();
- }
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::GetTwistDownElement:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TTwistDownElement* TTwistDownControl::GetTwistDownElement()
- {
- return fTwistDownElement;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::UpdateControlLocationTo: called by TTwistDownView::UpdateTwistDownControlLocations
- // TTwistDownDocument::UpdateTwistDownElements
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownControl::UpdateControlLocationTo(short rowNumber)
- {
- VRect theVRect = gZeroVRect;
- VPoint twistDownControlLocation = gZeroVPt;
- Boolean itsFocus = FALSE;
-
- fCoordinatesAreInvalid = TRUE; //Doing this tells everybody that this twistDownControl
- //needs to have its coordinates updated with a call to
- //UpdateCoordinates()
-
- short rowHeight = fTwistDownView -> GetRowHeight(1); //This is safe because if there
- //is a control there must be at
- //least one row.
-
- twistDownControlLocation.v = (long)(rowHeight*rowNumber - rowHeight);
- twistDownControlLocation.h = fTwistDownView -> fTwistDownControlLocation.h;
-
- this -> SetLocationTo(twistDownControlLocation);
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::UpdateControlSizeTo: called by TTwistDownDocument::UpdateTwistDownElements
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownControl::UpdateControlSizeTo()
- {
- fSize = fTwistDownView -> GetTwistDownControlSize();
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::SetLocationTo:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownControl::SetLocationTo(VPoint& itsLocation)
- {
- fLocation.v = itsLocation.v;
- fLocation.h = itsLocation.h;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::SuperViewChangedFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
- void TTwistDownControl::SuperViewChangedFrame(const VRect& oldFrame,
- const VRect& newFrame,Boolean invalidate)
- {
-
- fLocation.h = fTwistDownView -> fTwistDownControlLocation.h;
-
- Inherited::SuperViewChangedFrame(oldFrame,newFrame,invalidate);
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
- void TTwistDownControl::Draw(const VRect& area)
- {
- #pragma unused area
-
- if (fTwistDownElement -> TestShowSubListFlag())
- this -> DrawOpenTriangle();
- else
- this -> DrawClosedTriangle();
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::DoMouseUp:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TTwistDownControl::DoMouseUp(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
- {
- #pragma unused hysteresis
- TExpandElementCommand* anExpandElementCommand = NULL;
- TCollapseElementCommand* aCollapseElementCommand = NULL;
-
- //swallow a mouseUp event following a first click mouseDown event
- if (fTwistDownView -> fIsFirstClick == FALSE)
- {
- if (this -> ContainsMouse(theMouse) && event -> fIdentifier == mouseUp && this -> IsEnabled())
- {
- TTwistDownElement* targetElement = this -> GetTwistDownElement();
-
- if (targetElement -> TestHasSubListFlag()) //Make sure it is a folder. This is overkill because
- //if we get here it has to be a folder.
- {
- if (!targetElement -> TestShowSubListFlag()) //Make sure it isn't already expanded. This
- //test determines whether we're expanding
- //or collapsing.
- {
- if (targetElement -> CouldExpandElement()) //Make sure expanding won't exceed the
- //capacity of TTextListView
- {
- anExpandElementCommand = new TExpandElementCommand;
- anExpandElementCommand -> IExpandElementCommand(fTwistDownDocument, targetElement);
- if (gSendAppleEvents)
- anExpandElementCommand -> fUseAppleEvent = TRUE;
- this -> PostCommand(anExpandElementCommand);
- }
- else
- {
- CStr63 theDisplayedText;
- targetElement -> GetDisplayedText(theDisplayedText);
- gErrorParm3 = theDisplayedText;
- FailOSErr(errCantExpandElement); //I need to make it put up a different alert.
- }
- }
- else
- {
- //Because we don't want this to fail for out of memory reasons,
- //allocate it from temporary memory. //PGMacApp 550
- Boolean oldTemp = TemporaryAllocation(TRUE);
- Boolean oldArrayPerm = AllocateObjectsFromPerm(FALSE);
- aCollapseElementCommand = new TCollapseElementCommand;
- aCollapseElementCommand -> ICollapseElementCommand(fTwistDownDocument, targetElement);
- if (gSendAppleEvents)
- aCollapseElementCommand -> fUseAppleEvent = TRUE;
- this -> PostCommand(aCollapseElementCommand);
- oldArrayPerm = AllocateObjectsFromPerm(oldArrayPerm);
- oldTemp = TemporaryAllocation(oldTemp);
- }
- } //end if (fTwistDownElement -> TestHasSubListFlag())
- }
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
- void TTwistDownControl::DoEvent(EventNumber eventNumber, TEventHandler* source, TEvent* event)
- {
-
-
- switch (eventNumber)
- {
- case mExpandElement:
- {
- this -> DrawIntermediateTriangle();
- fNewHiliteState = noHilite;
- this -> DrawOpenTriangle();
- }
- break;
-
- case mCollapseElement:
- {
- this -> DrawIntermediateTriangle();
- fNewHiliteState = noHilite;
- this -> DrawClosedTriangle();
- }
- break;
-
- case mTurnOff:
- {
- fNewHiliteState = noHilite;
- this -> ForceRedraw();
- }
- break;
-
- default:
- Inherited::DoEvent(eventNumber, source, event);
- break;
-
- } //end switch (eventNumber)
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::Hilite:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
- void TTwistDownControl::Hilite()
- {
- VRect area;
- CRect qdArea;
-
- #if qDebug
- this -> AssumeFocused();
- #endif
-
- switch (fNewHiliteState)
- {
-
- case blackHilite:
- {
- this -> FillTriangleBlack();
- }
- break;
-
- case whiteHilite:
- {
- this -> FillTriangleWhite();
- }
- break;
-
- case noHilite:
- {
- //This could be the default case, but I think it is a little clearer written
- //explicitly as a case. At least this way, the casual reader knows the case
- //has been accounted for.
- }
- break;
-
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::HiliteState:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlNonRes
- void TTwistDownControl::HiliteState(Boolean state, Boolean redraw)
- {
- if (state != fHilite)
- {
- fHilite = state;
- if (state) // hilite adorner draws the hilite state
- {
- fNewHiliteState = blackHilite;
- }
- else
- {
- fNewHiliteState = whiteHilite;
- }
-
- if (redraw && this -> IsDrawable())
- {
- this -> Hilite();
- }
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::TrackMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TTwistDownControl::TrackMouse(TrackPhase aTrackPhase,
- VPoint& anchorPoint, VPoint& previousPoint, VPoint& nextPoint,
- Boolean mouseDidMove)
- {
- #pragma unused anchorPoint
- #pragma unused previousPoint
- #pragma unused mouseDidMove
- switch (aTrackPhase)
- {
- case trackBegin:
- {
- this -> HiliteState(TRUE, kRedraw);
- }
- break;
-
- case trackContinue:
- {
- this -> HiliteState(this->ContainsMouse(nextPoint), kRedraw);
- }
- break;
-
- case trackEnd:
- {
- fHilite = FALSE;
- if (this->ContainsMouse(nextPoint))
- {
- if (fTwistDownElement -> TestHasSubListFlag())
- {
- if (!fTwistDownElement -> TestShowSubListFlag())
- this -> HandleEvent(mExpandElement,this,NULL);
- else
- this -> HandleEvent(mCollapseElement,this,NULL);
- }
- }
-
- else
- {
- this -> HandleEvent(mTurnOff,this,NULL);
- }
-
- } //end case trackEnd
-
- break;
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::FillTriangleBlack:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
- void TTwistDownControl::FillTriangleBlack()
- {
- PolyHandle theTriangle = NULL;
-
- if (fTwistDownElement -> TestShowSubListFlag())
- {
- theTriangle = fTwistDownView -> GetOpenTriangle();
- FillPoly(theTriangle, &qd.black);
- FramePoly(theTriangle);
- }
- else
- {
- theTriangle = fTwistDownView -> GetClosedTriangle();
- FillPoly(theTriangle, &qd.black);
- FramePoly(theTriangle);
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::FillTriangleGray:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
- void TTwistDownControl::FillTriangleGray()
- {
- PolyHandle theTriangle = NULL;
-
- if (fTwistDownElement -> TestShowSubListFlag())
- {
- theTriangle = fTwistDownView -> GetOpenTriangle();
- FillPoly(theTriangle, &qd.ltGray);
- FramePoly(theTriangle);
- }
- else
- {
- theTriangle = fTwistDownView -> GetClosedTriangle();
- FillPoly(theTriangle, &qd.white);
- FramePoly(theTriangle);
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::FillTriangleWhite:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
- void TTwistDownControl::FillTriangleWhite()
- {
- PolyHandle theTriangle = NULL;
-
- if (fTwistDownElement -> TestShowSubListFlag())
- {
- theTriangle = fTwistDownView -> GetOpenTriangle();
- FillPoly(theTriangle, &qd.white);
- FramePoly(theTriangle);
- }
- else
- {
- theTriangle = fTwistDownView -> GetClosedTriangle();
- FillPoly(theTriangle, &qd.white);
- FramePoly(theTriangle);
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::EraseControlArea:
- //----------------------------------------------------------------------------------------
- #pragma segment MAControlRes
- void TTwistDownControl::EraseControlArea()
- {
- VRect area;
- CRect qdArea;
-
- #if qDebug
- this -> AssumeFocused();
- #endif
- this -> ControlArea(area);
- this -> ViewToQDRect(area, qdArea);
- EraseRect(qdArea);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::DrawClosedTriangle:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
- void TTwistDownControl::DrawClosedTriangle()
- {
- PolyHandle theTriangle = fTwistDownView -> GetClosedTriangle();
- FillPoly(theTriangle, &qd.ltGray);
- FramePoly(theTriangle);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::DrawOpenTriangle:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
- void TTwistDownControl::DrawOpenTriangle()
- {
- PolyHandle theTriangle = fTwistDownView -> GetOpenTriangle();
- FillPoly(theTriangle, &qd.ltGray);
- FramePoly(theTriangle);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownControl::DrawIntermediateTriangle:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
- void TTwistDownControl::DrawIntermediateTriangle()
- {
- long dontCare;
-
- this -> EraseControlArea();
-
- PolyHandle theTriangle = fTwistDownView -> GetIntermediateTriangle();
- FillPoly(theTriangle, &qd.black);
- FramePoly(theTriangle);
- Delay(8, &dontCare);
- this -> EraseControlArea();
- }
-
- #pragma segment Inline